﻿using System.Web.Profile;
using System.Web.Security;
using AspAuthentication.Interfaces;
using AspAuthentication.Providers;

namespace AspAuthentication
{
    /// <summary>
    /// Defines the class SecurityCop
    /// </summary>
    public class SecurityCop : ISecurityCop
    {
        private IPortalMembershipProvider _memebershipProvider;
        private IPortalProfileProvider _profileProvider;
        private IPortalRoleProvider _roleProvider;
        /// <summary>
        /// Gets or sets the forms gate keeper.
        /// </summary>
        /// <value>The forms gate keeper.</value>
        public IUserFormsAuthentication FormsGateKeeper { get; set; }
        /// <summary>
        /// Gets the portal membership provider.
        /// </summary>
        /// <value>The portal membership provider.</value>
        public IPortalMembershipProvider PortalMembershipProvider
        {
            get { return _memebershipProvider ?? (_memebershipProvider = (PortalMembershipProvider)Membership.Provider); }
        }

        /// <summary>
        /// Gets the portal role provider.
        /// </summary>
        /// <value>The portal role provider.</value>
        public IPortalRoleProvider PortalRoleProvider
        {
            get { return _roleProvider ?? (_roleProvider = (PortalRoleProvider)Roles.Provider); }
        }

        /// <summary>
        /// Gets the portal profile provider.
        /// </summary>
        /// <value>The portal profile provider.</value>
        public IPortalProfileProvider PortalProfileProvider
        {
            get { return _profileProvider ?? (_profileProvider = (PortalProfileProvider)ProfileManager.Provider); }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SecurityCop"/> class.
        /// </summary>
        public SecurityCop()
        {
            FormsGateKeeper = new UserFormsAuthentication();
        }
    }
}